package tests;

import static org.junit.Assert.assertTrue;

import java.math.BigInteger;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import components.RSACracker;
import components.RSAWienerBreaker;
import components.Rsa;

public class TestWiener {
	Rsa myRsa;
	BigInteger[] pubKey;
	BigInteger[] privKey;
	RSAWienerBreaker breaker;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	/**
	 * Iterate through 15 messages then encipher/decipher each of them.
	 * Check for equality between the initial message and the message
	 * returned after the enciphering/deciphering process.
	 */
	public void testEncipherDecipher() {

		// for(int i = 4; i < 10; i++){
		// myRsa = new Rsa(i); //Initialize an Rsa instance, with p and q each
		// using 4 bits.
		myRsa = new Rsa(2048, "weiner");
		pubKey = myRsa.getBigPubKey();
		privKey = myRsa.getBigPrivKey();
		RSACracker cracker = new RSACracker();

		System.out.println("Public Key (n, e): (" + pubKey[0] + ", "
				+ pubKey[1] + ")");
		System.out.println("Private Key (n, d): (" + privKey[0] + ", "
				+ privKey[1] + ")");
		BigInteger d = cracker.wienerAttack(myRsa.getRSAPubKey()).getExp();
		System.out.println(d);

		assertTrue(d.intValue() == privKey[1].intValue());
		// }

	}
}
